home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1987 / 07 / holub.exp < prev    next >
Text File  |  1987-07-28  |  2KB  |  68 lines

  1.  
  2.            #include <stdarg.h>
  3.  
  4.            static  doprnt(ofunct, funct_arg, fmt, argp)
  5.            int     (*ofunct)();
  6.            char    *funct_arg;
  7.            char    *fmt;
  8.            va_list *argp;
  9.            {
  10.                /* A doprnt() for ANSI                              */
  11.                /*          (c) Copyright 1987, Allen I. Holub.     */
  12.  
  13.                char        buf[133], *p ;
  14.  
  15.                vsprintf( buf, fmt, argp );
  16.                for( *p = buf; *p; (*ofunct)( *p++, funct_arg ) )
  17.                    ;
  18.            }
  19.  
  20. Example 1: A doprnt() for ANSI
  21.  
  22.  
  23.  
  24.  
  25.          #include <varargs.h>
  26.  
  27.          static  doprnt(ofunct, funct_arg, fmt, argp)
  28.          int     (*ofunct)();
  29.          char    *funct_arg;
  30.          char    *fmt;
  31.          va_list argp;
  32.          {
  33.              /* A doprnt() for Unix.                             */
  34.              /*          (c) Copyright 1987, Allen I. Holub.     */
  35.  
  36.              int         c                ;
  37.              extern char *mktemp()        ;
  38.              static char *tmp_name        ;
  39.              static FILE *tmp_file = NULL ;
  40.  
  41.              if( !tmp_file )
  42.              {
  43.                  tmp_name = mktemp("yyXXXXXX");
  44.  
  45.                  if( !(tmp_file = fopen(tmp_name , "w+")) )
  46.                  {
  47.                      fprintf(stderr,"Can't open temporary file %s\n",
  48.                                                          tmp_name );
  49.                      exit( 1 );
  50.                  }
  51.              }
  52.  
  53.              _doprnt( fmt, argp, tmp_file );
  54.  
  55.              putc   ( 0, tmp_file );
  56.              rewind (    tmp_file );
  57.  
  58.              while( (c = getc(tmp_file)) != EOF && c )
  59.                      (*ofunct)( c, funct_arg );
  60.              
  61.              rewind( tmp_file );         /* Get ready for next call */
  62.          }
  63.  
  64.  
  65. Example 2: A doprnt() for Unix
  66.  
  67. 
  68.